package com.centaline.androidsalesblog.widgets;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.centaline.androidsalesblog.R;

/**
 * 收藏的view
 * Created by guilin on 16/3/21.
 */
public class CollectView extends RelativeLayout {

    private ImageView img_collect;
    private AppCompatTextView atv_collect;

    private boolean collect;
    private String collectId;

    public CollectView(Context context) {
        this(context, null);
    }

    public CollectView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CollectView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.layout_collect, this);
        img_collect = (ImageView) findViewById(R.id.img_collect);
        atv_collect = (AppCompatTextView) findViewById(R.id.atv_collect);
    }

    /**
     * 设置收藏状态
     */
    public void setCollect(boolean collect) {
        this.collect = collect;
        updateUi();
    }

    /**
     * 是否收藏
     */
    public boolean isCollect() {
        return collect;
    }

    public String getCollectId() {
        return collectId;
    }

    public void setCollectId(String collectId) {
        this.collectId = collectId;
    }

    private void updateUi() {
        img_collect.setImageResource(collect ? R.drawable.ic_collect_selected : R.drawable.ic_collect_normal);
        atv_collect.setText(collect ? "已收藏" : "收藏");
        final String color = collect ? "#FFF13E06" : "#FF666666";
        atv_collect.setTextColor(Color.parseColor(color));
    }

}
